﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks.Dataflow;

namespace BinaryComparison
{
    public class FileReadBlock
    {
        private string _filePath;
        private int _bufferSize;
        private FileStream _fs;
        private FileStream _ks;
        private readonly byte[] _pattern;

        public FileReadBlock(string filePath, int bufferSize, byte[] pattern)
        {
            _filePath = filePath;
            _bufferSize = bufferSize;
            _pattern = pattern;
            _fs = new FileStream(_filePath, FileMode.Open, FileAccess.Read);
            _ks = new FileStream(_filePath, FileMode.Open, FileAccess.Read);
        }
        public FileStream GetFileStream2()
        {
            return _ks;
        }

        public FileStream GetFileStream()
        {
            return _fs;
        }

        public IEnumerable<byte[]> ReadBytes()
        {
            byte[] buffer = new byte[_bufferSize];
            while (true)
            {
                int len = _fs.Read(buffer, 0, _bufferSize);

                if (len == _pattern .Length- 1)
                {
                    yield break; 
                }
                yield return buffer[..len]; 
            }
        }

      
        public void CloseFileStream()
        {
            _fs?.Close();
            _ks?.Close();
        }
    }
}